How many frames `sprite` has. 0 if no sprite is set.
frame_count: int (read-only)How many frames sprite has, read-only - 0 if no sprite is set. Exists mainly so other code does not have to hard-code a sprite's own frame count by hand, which breaks the moment the art changes; write logic against frame_count instead and it stays correct if the sprite sheet grows or shrinks.
This only ever answers for whichever sprite THIS instance currently shows. To ask the same question about a sprite asset directly - one this instance is not necessarily showing - use sprite_frames instead, which takes the sprite as an argument.
if (frame >= frame_count - 1) {
frame = 0;
}A hand-written wraparound - the same ending frame_speed reaches on its own, spelled out for a case where you are advancing frame yourself instead (a state-driven animation that only sometimes plays forward).